@extends('backstage.layout.master')
@section('title', '添加优惠券')
@section('style')
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="/assets/css/jquery-ui-1.10.3.custom.min.css"/>
    <link rel="stylesheet" href="/assets/css/chosen.css"/>
    <link rel="stylesheet" href="/assets/css/datepicker.css"/>
    <link rel="stylesheet" href="/assets/css/bootstrap-timepicker.css"/>
    <link rel="stylesheet" href="/assets/css/daterangepicker.css"/>
    <link rel="stylesheet" href="/assets/css/colorpicker.css"/>
    <!-- fonts -->
    <style type="text/css">
        input.button {
            padding: 5px 15px 5px;
            margin: 2px 2px;
            border: none;
            background: #24a0d6;
            color: #FFF;
            cursor: pointer;
        }
        #fav_num{
            width: 20%;
        }
        #form-field-select-2 {
            width: 50%;
            margin-right: 6%;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="/backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/coupons/couponslist">优惠券 </a>
            </li>
            <li>
                <a href="/backstage/coupons/addcoupons">添加优惠券</a>
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        优惠券
                        <small>
                            <i class="icon-double-angle-right"></i>
                            优惠券
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="alert alert-info">
                            <i class="icon-hand-right"></i>
                            <!-- 信息-->
                        </div>
                        <div class="space-4"></div>
                        <form class="form-horizontal" role="form" action= "/backstage/coupons/addcoupons" method="post" enctype="multipart/form-data">
                            <div class="form-group {{$errors->first('name')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 优惠券名称</label>

                                <div class="col-sm-4">
                                    <input type="text" name="name" value="{{ old('name') }}" placeholder="优惠券名称" class="width-100" id="name">
									<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline" id="name_warn"> {{$errors->first('name')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('channel_id')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" >渠道</label>
                                <div class="col-sm-4">
                                    <input type="text" maxlength=4 name="channel_id"  class="width-100"
                                    id="channel_id" value="{{ old('channel_id') }}">
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="channel_id_error"> {{$errors->first('channel_id')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group ">
                                <label class="col-sm-3 control-label no-padding-right {{$errors->first('coupon_type')!=""?'has-error':''}}" for="form-field-1">优惠类型</label>
                                <div class="col-sm-4">
                                    <select name="coupon_type" class="form-control" id="form-field-select-1">
                                        <option @if(old('coupon_type') == 1)selected @endif value=1>优惠券(满减)</option>
                                        <option @if(old('coupon_type') == 2)selected @endif value=2>现金券</option>
                                    </select>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('binding_type')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('num')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" > 数量 </label>

                                <div class="col-sm-4">
                                    <input type="number" name="num" min=1 value="{{ old('num') }}" step="1"
                                           placeholder="优惠劵数量"
                                           class="width-100" id="coupon_num">
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"id="coupon_num_warn"> {{$errors->first('num')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('price')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right">优惠券面额</label>

                                <div class="col-sm-4">
                                    <input type="number" name="price" min=0 value="{{ old('price') }}"
                                           placeholder="优惠劵金额，保留两位小数"
                                           class="width-100" id="price" step="0.01">
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline" id="price_warn"> {{$errors->first('price')}}</div>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <div class="form-group ">
                                <label class="col-sm-3 control-label no-padding-right {{$errors->first('binding_type')!=""?'has-error':''}}" for="form-field-1">绑定类型</label>
                                <div class="col-sm-4">
                                    <select name="binding_type" class="form-control" id="form-field-select-1">
                                        <option @if(old('binding_type') == 1)selected @endif value=1>单券</option>
                                        <option @if(old('binding_type') == 2)selected @endif value=2>礼包券</option>
                                    </select>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('binding_type')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('date-range-picker')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 活动时间</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control"  name="date-range-picker" id="form-field-8"
                                           placeholder="点击选择"/>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('date-range-picker')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group {{$errors->first('desc')!=""?'has-error':''}}">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 优惠说明</label>

                                <div class="col-sm-4">
                                    <textarea class="form-control" name="desc" id="form-field-8"
                                              placeholder="优惠说明">{{ old('desc') }}</textarea>
                                </div>
                                <div class="col-sm-5">
                                    <div class="help-block col-xs-12 col-sm-reset inline"> {{$errors->first('desc')}}</div>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-3 col-md-9">
                                    <button class="btn btn-info" type="submit">
                                        <i class="icon-ok bigger-110"></i>
                                        创建
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
<script src="backstage/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="backstage/assets/js/date-time/bootstrap-timepicker.min.js"></script>
<script src="backstage/assets/js/date-time/moment.min.js"></script>
<script src="backstage/assets/js/date-time/daterangepicker.min.js"></script>
<script type="text/javascript">
 _token = '{{csrf_token()}}';
 $(function() {
   $('input[name=date-range-picker]').daterangepicker().prev().on(ace.click_event, function () {
       $(this).next().focus();
            });
     $("#channel_id").blur(function(){
         var reg=/^.*[\u4e00-\u9fa5]+.*$/;
         var channel_id=$("#channel_id").val();
         if( channel_id==""||channel_id==undefined)
         {
             $("#channel_id_error").html("请填写渠道");
             $("#channel_id_error").css("color","red");
         }else if(channel_id.length<4||channel_id.length>4){
             $("#channel_id_error").html("长度有误！");
             $("#channel_id_error").css("color","red");
         }else if(reg.test(channel_id)) {
             $("#channel_id_error").html("渠道里无中文！");
             $("#channel_id_error").css("color","red");
         }else{
             $.ajax({
                 type: "POST",
                 url: "/backstage/coupons/check-channel-id",
                 data: {'channel_id':channel_id},
                 success: function (msg) {
                     if (msg.state == 1) {
                         $('#channel_id_error').html('可使用');
                         $("#channel_id_error").css("color","#0044cc");
                     }else if(msg.state==2) {
                         $('#channel_id_error').html('已使用');
                         $("#channel_id_error").css("color","red");
                     }
                 }, error: function () {
                     swal({
                         title: "系统繁忙！",
                         text: "",
                         type: "error",
                         timer:2000
                     });
                 }
             });
         }
         return;
     });
 });
 function trim(s){
   return s.replace(/(^\s*)|(\s*$)/g, "");
 }
</script>
@stop
